package com.ayz.gateway.client.executor;


import com.ayz.gateway.client.exception.ExecuteRequestException;

import java.util.concurrent.TimeoutException;
/**
 * @ClassName RequestExecutor
 * @Description TODO: 请求执行器,执行具体的请求发出操作
 * @Author 快乐的星球
 * @Date 2023/5/20 11:12
 * @Version 1.0
 **/
public interface RequestExecutor<Req,Resp>{
    /**
     * 同步发出请求
     * @param request 请求
     * @param timeoutMills 请求超时时间,如果是0默认为没有超时时间，单位为毫秒
     * @return 响应
     * @throws TimeoutException 请求超时
     * @throws ExecuteRequestException 请求处理失败
     */
    Resp request(Req request,long timeoutMills) throws TimeoutException, ExecuteRequestException;

    /**
     * 异步的执行请求
     * @param request 请求对象
     * @param responseCallback 响应的回调函数
     * @throws TimeoutException
     * @throws ExecuteRequestException
     */
    void asyncRequest(Req request,ResponseCallback<Resp> responseCallback) throws TimeoutException,ExecuteRequestException;

    /**
     * 向服务器发起请求不期望结果
     * @param request
     * @throws ExecuteRequestException
     */
    void requestOneway(Req request) throws ExecuteRequestException;
}
